[Bug] Reject invalid vocab-parallel CE labels - #4297
Merged
tianyu-l merged 1 commit intoAug 24, 2026
Merged
Conversation
taking-lying-flat
requested review from
fegin,
tianyu-l,
wconstab and
wwwjn
as code owners
August 23, 2026 08:57
taking-lying-flat
force-pushed
the
fix/vocab-parallel-invalid-label-grad
branch
from
August 23, 2026 12:23
9b886cb to
29147b2
Compare
tianyu-l
approved these changes
Aug 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Why
For a label below zero other than IGNORE_INDEX, or a label greater than or equal to global_vocab_size, every TP rank treats the target as outside its local vocabulary shard. The forward path therefore clears every local target log-probability and all-reduces them to a zero loss. The backward path still retains the softmax term, however, and returns a nonzero logits gradient. That loss and gradient cannot describe the same mathematical function.
The previous version of this PR masked those gradients in backward. Although that restored forward/backward consistency, it silently treated malformed labels like ignored labels and diverged from regular cross entropy, which rejects out-of-range targets. Validating in forward is the smaller and safer contract: bad training data fails immediately instead of being hidden, and backward needs no special case.
Labels are replicated across the TP dimension, so every rank evaluates the same predicate. The check happens before the shard-local label transformation and before TP collectives.
Validation
Only the production file is included; no test files are committed.